//! \file linux_ptrace_utils.h

#include <link.h>
#include <sys/ptrace.h>
#include <sys/user.h>
#include "check.h"
#include "defs.h"

//-----------------------------------------------------------------------------

#ifndef _LINUX_PTRACE_UTILS_H_
#define _LINUX_PTRACE_UTILS_H_

//-----------------------------------------------------------------------------

typedef struct {
    int pid;
    bool attached;
} ptrace_session;

//-----------------------------------------------------------------------------

TBGError PtraceOpen(int pid, ptrace_session *pps);

TBGError PtraceClose(ptrace_session *pps);

TBGError PtraceDump(ptrace_session *pps);

TBGError PtraceAttach(ptrace_session *pps);

TBGError PtraceDetach(ptrace_session *pps);

TBGError PtraceReadByteData(ptrace_session *pps, unsigned long addr,
                            void *vptr, unsigned int len);

TBGError PtraceReadData(ptrace_session *pps, unsigned long addr, void *vptr,
                        unsigned int len_in_addrs);

TBGError PtraceReadStr(ptrace_session *pps, unsigned long addr,
                       unsigned int len, char *ret);

TBGError PtraceWriteData(ptrace_session *pps, unsigned long addr, void *vptr,
                         unsigned int len_in_addrs); 

TBGError PtraceGetRegs(ptrace_session *pps, struct user_regs *regs); 

//-----------------------------------------------------------------------------

#endif // _LINUX_PTRACE_UTILS_H_
